package com.cysion.study.ui

import android.support.v7.widget.LinearLayoutManager
import com.cysion.other.color
import com.cysion.study.R
import com.cysion.study.adapter.POrderTeacherAdapter
import com.cysion.study.entity.ProcessLists
import com.cysion.study.helper.UserCache
import com.cysion.study.ktbox.Box.context
import com.cysion.study.ktbox.base.BaseActivity
import com.cysion.study.ktbox.base.ITEM_CLICK
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.study.ktbox.utils.darkTextTheme
import com.cysion.study.net.ApiClient
import com.cysion.study.uibox.bar.TopBar
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.widget.ShowToast
import com.cysion.targetfun._subscribe
import kotlinx.android.synthetic.main.activity_backmoney_detail.*

class PBackMoneDetailActivity :BaseActivity(){
    override fun getLayoutId(): Int {
        return R.layout.activity_backmoney_detail
    }

    private var id=""
    override fun initView() {
        id = intent.extras.getString("id")
        darkTextTheme(color(R.color.white))
        topbar.apply {
            setTitleBackColor(color(R.color.white))
            setTitle("退款详情")
            setOnTopBarClickListener { obj, pos ->
                if (pos == TopBar.Pos.LEFT) {
                    finish()
                }
            }
        }

    }

    override fun initData() {
        super.initData()
        getData()
    }
    private fun getData() {
        Alert.loading(self)
        ApiClient.api.getBalanceDetails(UserCache.token,id).compose(
            BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    Alert.close()

//                    tv_money.text=it.
                    tv_back_what.text="退款理由："+it.refundReason
                    tv_card.text="退款课时数："+it.orderTotalNumber
                    tv_bank.text="退款金额："+it.refundMoney
                    tv_bank_name.text="提交退款申请时间："+it.refundCreateTime
                    tv_confirm_time.text="确认退款时间："+it.refundReplyTime

                    dataList.clear()
                    dataList.addAll(it.processList)
                    mAdapter.notifyDataSetChanged()

                    //订单信息
                    tv_name.text="订单号："+it.orderNo
                    tv_phone.text="学员账号："+it.orderPhone
                    tv_time.text="下单时间："+it.orderCreateTime
                    tv_num.text="付款时间："+it.orderPayTime
                    tv_confirm.text="课时数："+it.orderTotalNumber
                    tv_price.text="课时单价："+it.orderCourseMoney
                    tv_total_money.text="课时总价："+it.orderTotalMoney
                    tv_now_money.text="实付："+it.orderPayMoney
                }
                _onError {
                    Alert.close()
                    ShowToast(ErrorHandler.handle(it).errorMsg)
                }
            }
    }

    //退款进度list
    private lateinit var mAdapter: POrderTeacherAdapter
    private val dataList: MutableList<ProcessLists> = mutableListOf()
    //初始化列表
    private fun initRecyclerView() {
        rv_list.isNestedScrollingEnabled = false
        mAdapter = POrderTeacherAdapter(dataList, context)
        rv_list.adapter = mAdapter
        rv_list.layoutManager = LinearLayoutManager(context)
        mAdapter.setOnTypeClickListener { obj, position, flag ->
            if (flag == ITEM_CLICK) {//
            }
        }
    }


    override fun closeMvp() {
    }

}
